package br.com.musclebook.service;

import java.util.List;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.inject.Inject;

import br.com.musclebook.entity.Exercise;
import br.com.musclebook.enums.ExerciseCategory;

@Stateless
public class ExerciseService {
    
    @Inject
    private ExerciseDAO exerciseDAO;
    
    @TransactionAttribute(TransactionAttributeType.SUPPORTS)
    public Exercise find(Long id) {
	return this.exerciseDAO.find(id);
    }
    
    @TransactionAttribute(TransactionAttributeType.SUPPORTS)
    public List<Exercise> listByCategory(ExerciseCategory category, Long userId) {
	return this.exerciseDAO.listByCategory(category, userId);
    }
    
    @TransactionAttribute(TransactionAttributeType.SUPPORTS)
    public List<Exercise> listByName(String name, Long userId) {
	if(name == null || "".equals(name.trim()))
	    return null;
	
	return this.exerciseDAO.listByName(name, userId);
    }
    
    @TransactionAttribute(TransactionAttributeType.SUPPORTS)
    public List<String> listNames(String name, Long userId) {
	return this.exerciseDAO.listNames(name, userId);
    }
    
    public Exercise insert(Exercise userExercise) {
	return this.exerciseDAO.insert(userExercise);
    }
    
    public Exercise update(Exercise userExercise) {
	return this.exerciseDAO.update(userExercise);
    }

}
